package com.netease.stat.a;

import com.netease.framework.a.m;
import com.netease.framework.b.c;
import com.netease.framework.b.d;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.zip.GZIPOutputStream;
import org.apache.http.entity.ByteArrayEntity;
import org.json.JSONException;
import org.json.JSONObject;

public class a extends com.netease.framework.b.a
  implements d
{
  private static final String A = "/data/data/%s/stfiles/";
  static SimpleDateFormat a = null;
  protected static final int b = 65536;
  protected static final int c = 65537;
  protected static final int d = 65538;
  protected static final int e = 65539;
  private static final int l = 8192;
  private static byte[] m = "-------848c2a30-8ff6-4e4a-8e77-a2e8a99d3ce2-dfc1a2a6-d7f4-41a4-aec5-e7ec4fc37508".getBytes();
  private static Object[] n = new Object[0];
  private static ByteArrayOutputStream o;
  private static GZIPOutputStream p;
  private static final boolean q = false;
  private static final String z = "StatTranscation";
  JSONObject f;
  LinkedList g;
  boolean i;
  boolean j;
  String k;

  private a(int paramInt, String paramString, JSONObject paramJSONObject, LinkedList paramLinkedList, boolean paramBoolean1, boolean paramBoolean2)
  {
    super(paramInt);
    this.k = paramString;
    this.f = paramJSONObject;
    this.g = paramLinkedList;
    this.i = paramBoolean1;
    this.j = paramBoolean2;
  }

  private a(String paramString, boolean paramBoolean)
  {
    super(65538);
    this.k = paramString;
    this.j = paramBoolean;
  }

  protected static a a(String paramString, JSONObject paramJSONObject, LinkedList paramLinkedList, boolean paramBoolean1, boolean paramBoolean2)
  {
    return new a(65539, paramString, paramJSONObject, paramLinkedList, paramBoolean1, paramBoolean2);
  }

  public static a a(String paramString, JSONObject paramJSONObject, boolean paramBoolean)
  {
    return new a(65537, paramString, paramJSONObject, null, false, paramBoolean);
  }

  protected static a a(String paramString, boolean paramBoolean)
  {
    return new a(paramString, paramBoolean);
  }

  private static String a(String paramString, byte[] paramArrayOfByte)
  {
    Object localObject = null;
    if ((paramString == null) || (paramArrayOfByte == null));
    while (true)
    {
      return localObject;
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[0] = paramString;
      File localFile1 = new File(String.format("/data/data/%s/stfiles/", arrayOfObject));
      try
      {
        if (!localFile1.exists())
          localFile1.mkdirs();
        File localFile2 = new File(localFile1, a().format(Calendar.getInstance().getTime()) + ".st");
        localFile2.createNewFile();
        FileOutputStream localFileOutputStream = new FileOutputStream(localFile2);
        localFileOutputStream.write(paramArrayOfByte);
        localFileOutputStream.close();
        String str = localFile2.getPath();
        localObject = str;
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
      }
    }
  }

  private static SimpleDateFormat a()
  {
    if (a == null)
      a = new SimpleDateFormat("yyyyMMddHHmmssSSS", Locale.ENGLISH);
    return a;
  }

  private static void a(String paramString)
  {
    File localFile = new File(paramString);
    try
    {
      if (localFile.exists())
        localFile.delete();
      label21: return;
    }
    catch (Exception localException)
    {
      break label21;
    }
  }

  public static void a(String paramString, JSONObject paramJSONObject, LinkedList paramLinkedList)
  {
    if ((o != null) || (paramLinkedList.size() > 0))
    {
      a(paramJSONObject, paramLinkedList);
      a(paramString, b());
    }
  }

  private static void a(JSONObject paramJSONObject, List paramList)
  {
    if (paramJSONObject == null);
    String str;
    do
    {
      return;
      str = b(paramJSONObject, paramList);
    }
    while (str == null);
    byte[] arrayOfByte = str.getBytes();
    try
    {
      while (true)
      {
        synchronized (n)
        {
          if ((o == null) || (p == null))
          {
            o = new ByteArrayOutputStream();
            p = new GZIPOutputStream(o);
            p.write(arrayOfByte);
          }
        }
        p.write(m);
      }
    }
    catch (IOException localIOException)
    {
      while (true)
        localIOException.printStackTrace();
    }
  }

  private static void a(byte[] paramArrayOfByte)
  {
    int i1 = 30;
    if (paramArrayOfByte == null)
      return;
    if (paramArrayOfByte.length > i1);
    while (true)
    {
      for (int i2 = 0; i2 < i1; i2++)
        paramArrayOfByte[i2] = (byte)(0xD2 ^ paramArrayOfByte[i2]);
      break;
      i1 = paramArrayOfByte.length;
    }
  }

  public static a b(String paramString, JSONObject paramJSONObject, LinkedList paramLinkedList, boolean paramBoolean1, boolean paramBoolean2)
  {
    return new a(65536, paramString, paramJSONObject, paramLinkedList, paramBoolean1, paramBoolean2);
  }

  private static String b(JSONObject paramJSONObject, List paramList)
  {
    StringBuilder localStringBuilder = new StringBuilder();
    String str = paramJSONObject.toString();
    int i1 = str.lastIndexOf('}');
    if ((paramList != null) && (i1 > 0))
    {
      localStringBuilder.append(str.substring(0, i1)).append(',');
      localStringBuilder.append('"').append("events").append('"');
      localStringBuilder.append(":[");
      Iterator localIterator = paramList.iterator();
      while (localIterator.hasNext())
        localStringBuilder.append((String)localIterator.next()).append(',');
      if (paramList.size() > 0)
        localStringBuilder.deleteCharAt(-1 + localStringBuilder.length());
      localStringBuilder.append(']').append('}');
      str = localStringBuilder.toString();
    }
    return str;
  }

  private static byte[] b()
  {
    Object localObject1 = null;
    synchronized (n)
    {
      try
      {
        if ((o != null) && (p != null))
        {
          p.close();
          byte[] arrayOfByte = o.toByteArray();
          localObject1 = arrayOfByte;
        }
        p = null;
        o = null;
        if (localObject1 != null)
          a(localObject1);
        return localObject1;
      }
      catch (IOException localIOException)
      {
        while (true)
          localIOException.printStackTrace();
      }
    }
  }

  private static byte[] b(String paramString)
  {
    try
    {
      File localFile = new File(paramString);
      if (localFile.exists())
      {
        FileInputStream localFileInputStream = new FileInputStream(localFile);
        arrayOfByte = new byte[localFileInputStream.available()];
        localFileInputStream.read(arrayOfByte);
        localFileInputStream.close();
        return arrayOfByte;
      }
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      while (true)
      {
        localFileNotFoundException.printStackTrace();
        byte[] arrayOfByte = null;
      }
    }
    catch (Exception localException)
    {
      while (true)
        localException.printStackTrace();
    }
  }

  private static boolean f()
  {
    int i1 = 0;
    synchronized (n)
    {
      if (o != null)
        if (o.size() > 8192)
          i1 = 1;
    }
    return i1;
  }

  private void p()
  {
    int i1 = 0;
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[i1] = this.k;
    File localFile = new File(String.format("/data/data/%s/stfiles/", arrayOfObject));
    try
    {
      if (localFile.exists())
        if (localFile.isDirectory())
        {
          String[] arrayOfString = localFile.list(new b(this));
          if (arrayOfString.length > 0)
          {
            Arrays.sort(arrayOfString);
            while (i1 < -10 + arrayOfString.length)
            {
              new File(localFile, arrayOfString[i1]).delete();
              i1++;
            }
            a locala2 = a(new File(localFile, arrayOfString[i1]).getPath(), this.j);
            locala2.a(this);
            g().a(locala2);
            return;
          }
        }
        else
        {
          localFile.delete();
        }
      a locala1 = a(this.k, this.f, this.g, this.i, this.j);
      locala1.a(this);
      g().a(locala1);
    }
    catch (Exception localException)
    {
      while (true)
        localException.printStackTrace();
    }
  }

  public void a(int paramInt1, int paramInt2, int paramInt3, Object paramObject)
  {
    switch (paramInt2)
    {
    default:
    case 65538:
    case 65539:
    }
    while (true)
    {
      return;
      p();
      continue;
      c(paramInt1, this.g);
      h();
    }
  }

  protected void a(int paramInt, Object paramObject)
  {
    switch (n())
    {
    default:
    case 65539:
    case 65538:
    case 65537:
    }
    do
      while (true)
      {
        c(paramInt, this.g);
        return;
        if ((!this.i) || (this.k == null))
          continue;
        a(this.k);
        continue;
        a(this.k);
      }
    while ((paramObject == null) || (!(paramObject instanceof String)));
    while (true)
    {
      try
      {
        JSONObject localJSONObject = new JSONObject((String)paramObject);
        if (200 != localJSONObject.optInt("code"))
          break;
        localObject = localJSONObject.optString("logserver");
        if ((localObject == null) || (((String)localObject).length() <= 0))
          break;
        if ((!((String)localObject).startsWith("http://")) && (!((String)localObject).startsWith("https://")))
          break label255;
        if (((String)localObject).endsWith("/"))
          continue;
        localObject = (String)localObject + "/";
        com.netease.stat.a.a((String)localObject + "log");
        a locala = b(this.k, this.f, null, false, this.j);
        g().a(locala);
      }
      catch (JSONException localJSONException)
      {
        localJSONException.printStackTrace();
      }
      break;
      label255: String str = "http://" + (String)localObject;
      Object localObject = str;
    }
  }

  public void b(int paramInt1, int paramInt2, int paramInt3, Object paramObject)
  {
    d(paramInt1, null);
    h();
  }

  protected void b(int paramInt, Object paramObject)
  {
    d(paramInt, paramObject);
  }

  public void c()
  {
    String str;
    byte[] arrayOfByte;
    switch (n())
    {
    default:
      str = null;
      arrayOfByte = null;
    case 65536:
    case 65538:
    case 65539:
    case 65537:
    }
    while (true)
    {
      if ((arrayOfByte != null) && (str != null))
      {
        m localm = new m(str, com.netease.framework.a.b.b);
        localm.a(new ByteArrayEntity(arrayOfByte));
        a(localm);
      }
      while (true)
      {
        return;
        if (!com.netease.stat.a.c(this.j))
        {
          d(0, null);
          h();
          continue;
        }
        p();
        h();
        continue;
        if (!com.netease.stat.a.c(this.j))
        {
          d(0, null);
          h();
          continue;
        }
        arrayOfByte = b(this.k);
        if (arrayOfByte == null)
        {
          c(0, null);
          h();
          continue;
        }
        str = com.netease.stat.a.a();
        break;
        str = com.netease.stat.a.a();
        if ((this.g != null) && (this.g.size() > 0))
        {
          if (str == null)
            break label327;
          a(this.f, this.g);
          this.g.clear();
          if (f())
          {
            arrayOfByte = b();
            this.k = a(this.k, arrayOfByte);
            this.i = true;
            if (com.netease.stat.a.c(this.j))
              break;
            d(0, null);
            h();
            continue;
          }
          c(0, this.g);
          h();
          continue;
        }
        c(0, this.g);
        h();
        continue;
        a(this.f, this.g);
        arrayOfByte = b();
        str = "http://analytics.hz.netease.com:8084/locate";
        break;
        d(0, null);
        h();
      }
      label327: arrayOfByte = null;
    }
  }
}

/* Location:           D:\android\hack\dex2jar-0.0.9.8\classes_dex2jar.jar
 * Qualified Name:     com.netease.stat.a.a
 * JD-Core Version:    0.6.0
 */